package com.example.eventbusdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.example.eventbusdemo.events.FirstEvent;
import com.example.eventbusdemo.events.FourthEvent;
import com.example.eventbusdemo.events.MessageEvent;
import com.example.eventbusdemo.events.SecondEvent;
import com.example.eventbusdemo.events.ThirdEvent;

import org.greenrobot.eventbus.EventBus;

/**
 * @author wdl
 */
public class SecondActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        Button btnSendMessage = findViewById(R.id.btn_send_message);
        Button btnPost1 = findViewById(R.id.btn_post_1);
        Button btnPost2 = findViewById(R.id.btn_post_2);
        Button btnPost3 = findViewById(R.id.btn_post_3);
        Button btnPost4 = findViewById(R.id.btn_post_4);
        btnSendMessage.setOnClickListener(this);
        btnPost1.setOnClickListener(this);
        btnPost2.setOnClickListener(this);
        btnPost3.setOnClickListener(this);
        btnPost4.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_send_message:
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        //4.发送事件
                        EventBus.getDefault().post(new MessageEvent("你好MainActivity", 0));
                    }
                }).start();
                break;
            case R.id.btn_post_1:
                EventBus.getDefault().post(new FirstEvent("FirstEvent"));
                break;
            case R.id.btn_post_2:
                EventBus.getDefault().post(new SecondEvent("SecondEvent"));
                break;
            case R.id.btn_post_3:
                EventBus.getDefault().post(new ThirdEvent("ThirdEvent"));
                break;
            case R.id.btn_post_4:
                EventBus.getDefault().post(new FourthEvent("FourthEvent"));
                break;
            default:
        }
    }
}
